package com.ktt.controller;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ktt.bean.Bis_custom_user;
import com.ktt.service.Bis_custom_userService;
import com.ktt.service.OrderService;
import com.ktt.service.UpService;
import com.sjh.vo.Bis_bisiness_order;
import com.xbw.bean.Bis_Shop;
import com.xbw.service.ShopService;
import com.zsy.bean.Bis_Shop_User;

@Controller
@RequestMapping("up")
public class UpController {

	@Autowired
	private Bis_custom_userService userService;
	@Autowired
	private ShopService shopService;
	@Autowired
	private OrderService orderService;
	@Autowired
	private UpService upService;

	//ǰ̨��ʾ
		@RequestMapping("/upList")
		public ModelAndView upList(Map map,HttpServletRequest request,HttpSession session,@RequestParam(value="page",defaultValue="1")int page){
			ModelAndView model=new ModelAndView();
			String mobile=request.getParameter("mobile");
			String qname=request.getParameter("qname");
			String born_date=request.getParameter("born_date");
			String beauty_num=request.getParameter("beauty_num");
			String bag_num=request.getParameter("bag_num");
			map.put("mobile", mobile);
			map.put("qname", qname);
			map.put("born_date", born_date);
			map.put("beauty_num", beauty_num);
			map.put("bag_num", bag_num);
			Bis_Shop_User bis=(Bis_Shop_User) session.getAttribute("shopuser");
			map.put("shop_id", bis.getShop_id());
			PageHelper.startPage(page, 5);
			List<Bis_custom_user> list=this.upService.listAll(map);
			PageInfo<Bis_custom_user> info=new PageInfo<>(list);
			model.addObject("map", map);
			model.addObject("info", info);
			model.setViewName("ktt/upList");
			return model;
		}
		//ǰ̨�鿴����
		@RequestMapping("/upMuchs/{id}")
		public String upMuchs(@PathVariable("id")int id,Model model){
			Bis_custom_user users=upService.getById(Integer.valueOf(id));
			model.addAttribute("users", users);
			return "ktt/upMuch";
		}
		
		//ǰ̨�鿴����
		@RequestMapping("/upOrderList/{id}")
		public ModelAndView upOrderList(@PathVariable("id")int id,Map map,HttpServletRequest request,@RequestParam(value="page",defaultValue="1")int page){
			ModelAndView model=new ModelAndView("upMoney");
			String order_id=request.getParameter("order_id");
			String order_content=request.getParameter("order_content");
			String pay_way=request.getParameter("pay_way");
			map.put("order_id", order_id);
			map.put("order_content", order_content);
			map.put("pay_way", pay_way);
			PageHelper.startPage(page, 2);
			List<Bis_bisiness_order> list=this.orderService.upList(map);
			PageInfo<Bis_bisiness_order> info=new PageInfo<>(list);
			List<Bis_Shop> list2=this.shopService.listAll(map);
			Bis_custom_user users=upService.getById(Integer.valueOf(id));
			model.addObject("users", users);
			model.addObject("map", map);
			model.addObject("info", info);
			model.addObject("list2", list2);
			model.setViewName("ktt/upMoney");
			return model;
		}
		
		@RequestMapping("/myList")
		public String myList(Model model,HttpSession session){
			Bis_Shop_User bis=(Bis_Shop_User) session.getAttribute("shopuser");
			Bis_bisiness_order order=(Bis_bisiness_order) this.orderService.getCount(bis.getShop_id());
			model.addAttribute("order", order);
			return "ktt/myList";
		}
}
